<?php
class Order {
    public $id;
    public $amount;

    public function __construct($id, $amount) {
        $this->id = $id;
        $this->amount = $amount;
    }
}

class User {
    public $id;
    public $name;
    public $orders = []; // 订单列表

    public function __construct($id, $name) {
        $this->id = $id;
        $this->name = $name;
    }

    public function addOrder($order) {
        $this->orders[] = $order;
    }
}

// 创建用户
$user = new User(1, "张三");

// 添加订单
$user->addOrder(new Order(101, 99.99));
$user->addOrder(new Order(102, 149.50));

// 转换为 JSON
$json = json_encode($user, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo $json;
?>